Linux 下安装多个版本的 CUDA(Ubuntu)
最近几个项目需要用到不同版本的 CUDA 来编译,所以这里记录一下怎么配置多版本的 CUDA 环境,以后就懒得再去百度了。
下载
CUDA Toolkit Download Link 这里是最新的 CUDA 版本地址,如果需要其他版本的话,需要在网页下方找到 Archive of Previous CUDA Releases.
安装
假定我们已经安装了某个版本的 CUDA
,在安装另一个版本的时候需要进行的操作如下,这里用 cuda_11.7.1_515.65.01_linux
做演示:
wget https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda_11.7.1_515.65.01_linux.run
sudo sh cuda_11.7.1_515.65.01_linux.run
接下来基本上是这样的步骤:
- 看到提示说推荐卸载现有版本再继续,直接选择
Continue
- EULA 协议,直接
accept
- 取消除了
CUDA Toolkit
的其他勾选 - 去
OPTION
里面设定CUDA Library
地址为:/usr/local/cuda-11.7/
- 确定安装
看到以下 Summary 就是成功了:
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-11.7/
Please make sure that
- PATH includes /usr/local/cuda-11.7/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-11.7/lib64, or, add /usr/local/cuda-11.7/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.7/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 515.00 is required for CUDA 11.7 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run --silent --driver
Logfile is /var/log/cuda-installer.log
最后,通过在 ~/.bashrc
或者 ~/.profile
添加以下命令实现切换版本:
export PATH=/usr/local/cuda-11.7/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib64:$LD_LIBRARY_PATH
export CUDA_HOME="/usr/local/cuda-11.7"